package com.junzhiit.nengji.dao.impl;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.bo.UserIncomeHistoryBO;
import com.junzhiit.nengji.dao.IncomeHistoryDAO;
import com.junzhiit.nengji.model.IncomeHistory;

@Repository
public class IncomeHistoryDAOImpl extends AbstractBaseDAO<IncomeHistory> implements IncomeHistoryDAO{

	@Override
	public UserIncomeHistoryBO totalUserIncomeHistory(String userId, String shopId,String date) {
		StringBuffer sql = new StringBuffer();
		sql.append("select ifnull(sum(commission_money),0) as incomeMoney,");
		sql.append(" (select ifnull(sum(money),0) from pay_history where shop_id = ? and date_format(created_time,'%Y-%m') = date_format(?,'%Y-%m')) as shopIncome");
		sql.append(" from income_history ih ");
		sql.append(" where ih.income_user_id = ? and ih.shop_id = ? and date_format(ih.created_time,'%Y-%m') = date_format(?,'%Y-%m')");
		StatementParameter params = new StatementParameter();
		params.setString(shopId);
		params.setString(date);
		params.setString(userId);
		params.setString(shopId);
		params.setString(date);
		return super.query(sql.toString(),UserIncomeHistoryBO.class,params);
	}

}
